<template>
  <div>
    <div class="container">
      <!--     ----search--- form-------->
      <form>
        <div class="search_bar">
          <div class="search">
            <div class="left">
              <!--          下拉选择-->
              <div class="block">
                <el-cascader
                  placeholder="职位类型"
                  v-model="value"
                  style="width: 120px"
                  :options="options"
                  :props="{ expandTrigger: 'hover' }"
                  @change="handleChange"></el-cascader>
              </div>
            </div>
            <!--        -->
            <div class="right">
              <el-autocomplete
                class="inline-input"
                v-model="state2"
                :fetch-suggestions="querySearch"
                placeholder="请输入内容"
                :trigger-on-focus="false"
                @select="handleSelect"
              ></el-autocomplete>
            </div>
          </div>
          <div class="btn">
            <button>搜索</button>
          </div>
        </div>
      </form>
      <!--      /form-------->
    </div>
  </div>
</template>

<script>
export default {
  name: 'SearchBox',
  data () {
    return {
      value: '',
      options: [],
      loading: true,
      input: '',
      state2: '',
      restaurants: [{
        value: '',
        address: ''
      }]
    }
  },
  methods: {
    querySearch (queryString, cb) {
      var restaurants = this.restaurants
      var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants
      // 调用 callback 返回建议列表的数据
      cb(results)
    },
    createFilter (queryString) {
      return (restaurant) => {
        return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0)
      }
    },
    handleChange () {
    },
    handleSelect () {
    }
  },
  mounted () {
    const that = this
    this.$ajax.get('api/api/v1/region/county', {
      params: {
        city_id: '5001'
      }
    }).then((res) => {
      if (res.data.data && res.status === 200) {
        const data = res.data.data
        data.forEach((value, index) => {
          that.options.push(value)
          that.options[index].value = value.county_id
          that.options[index].label = value.county_name
        })
      }
    })
    this.$ajax.get('api/api/v1/options').then((res) => {
      const data = res.data.data.education
      for (const item in data) {
        that.restaurants.push({})
        that.restaurants[item].value = data[item]
      }
    })
  }
}
</script>

<style lang="scss" scoped>
::v-deep .search_bar input {
  outline: none;
  border: none;
  border-radius: 0;
  width: 640px;
  height: 50px;
}

.search_bar {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  height: 50px;
  align-items: center;
  transition: .4s linear;
  padding: 0 150px;

  .search {
    display: flex;
    flex: 1;
    height: 50px;
    align-items: center;
    boder: 1px solid rgba(0, 0, 0, 0.2);
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);

    &:hover {
      border: 1px solid #5dd5c8;
      box-shadow: 0 1px 5px rgba(82, 202, 195, 0.2);
    }

    .left {

    }

    .right {
      width: 400px;
    }
  }

  .btn button {
    width: 140px;
    height: 50px;
    line-height: 50px;
    background-color: #55cbc4;
    text-align: center;
    outline: none;
    border: none;
    font-size: 16px;
    color: #ffffff;

    &:hover {
      background-color: #75e0d4;
    }
  }
}
</style>
